package com.daydayup.learn;

import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class CouponServiceImplV2 implements CouponServiceV2 {

    /**
     * 下发优惠券的数量
     */
    public static final Integer COUPON_NUMBER = 50;

    @Resource
    private ThreadPoolTaskExecutor threadPool;

    /**
     * 执行下发逻辑
     */
    @Override
    public void batchTaskAction() throws InterruptedException {
        // 1、模拟要下发的50条优惠券
        List<String> coupons = new ArrayList<>(COUPON_NUMBER);
        for (int i = 0; i < COUPON_NUMBER; i++) {
            coupons.add("优惠券---" + i);
        }
        long startTime = System.currentTimeMillis();
        TaskBatchSendUtils.send(coupons,threadPool,TaskBatchSendUtils::disposeTask);
        long endTime = System.currentTimeMillis();
        System.out.println("----任务处理完毕 costTime:"+(endTime-startTime)+"毫秒");
    }
}
